﻿using Shop.Collect;
using Shop.ExtendService;
using Shop.Model;
using WeDonekRpc.Client.Attr;
using WeDonekRpc.Client.Interface;
using WeDonekRpc.Helper;

namespace Shop.LocalEvent.GroupSpec
{
    [LocalEventName("Delete")]
    internal class DeleteGoodsSku : IEventHandler<GoodsSpecEvent>
    {
        private readonly IGoodsSkuCollect _GoodsSku;
        private readonly IFileService _File;
        public DeleteGoodsSku (IGoodsSkuCollect sku, IFileService file)
        {
            this._File = file;
            this._GoodsSku = sku;
        }

        public void HandleEvent (GoodsSpecEvent data, string eventName)
        {
            string specKey = string.Join(',', data.SpecId.OrderBy(a => a)).GetMd5();
            long? skuId = this._GoodsSku.Delete(data.GoodsId, specKey);
            if (skuId.HasValue)
            {
                this._File.Drop(new string[]
                {
                    ShopFileDirDic.GoodsImgShow,
                    ShopFileDirDic.GoodsSkuImg,
                    ShopFileDirDic.GoodsSkuCover
                }, skuId.Value);
            }
        }
    }
}
